package com.kevin.eshopcache.kafka;

import com.kevin.eshopcache.utils.ContextUtil;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @author: e20160504
 * @date: 2018/11/7
 * @desc
 */

@EnableAutoConfiguration
@Component
public class Consumer {

    @Autowired
    private ApplicationContext applicationContext;

    @Bean
    public void setContext(){
        ContextUtil.setApplicationContext(applicationContext);
    }

    @KafkaListener(topics = "cache-topic")
    public void run(ConsumerRecord<?, ?>  record) {
        new Thread(new Process(record)).start();
    }
}
